feat(core/inlines): support [[[SPEC#id]]] for cross-spec section links#5146
Conversation
02aca58 to
ca4f622
Compare
There was a problem hiding this comment.
Pull request overview
Extends ReSpec’s [[[...]]] inline expansion parsing so authors can cite a spec and link directly to a section using a fragment (e.g., [[[fetch#data-fetch]]]), leveraging existing data-cite fragment handling.
Changes:
- Updated the
[[[...]]]inline-expansion regex to allow an optional#fragmentsuffix. - Added a unit test asserting that
[[[fetch#data-fetch]]]resolves to the spec URL with the fragment and uses the spec title as link text.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/core/inlines.js |
Broadens inlineExpansion matching to include SPEC#fragment forms. |
tests/spec/core/inlines-spec.js |
Adds coverage for cross-spec section linking via [[[SPEC#id]]]. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@sidvishnoi Good point. The spec title alone isn't useful for section-level links. The intended behavior for The data for this is available in w3c/webref's headings data. I've opened speced/respec-web-services#469 to add a Holding this PR until the headings API is available and the inlines.js expansion can use real heading text. Will also add alias support ( |
2de2f1e to
da52313
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot Can you check and fix any issues identified by ci? |
Head branch was pushed to by a user without write access
Fixed in 8c873cf. The CI failures were caused by my The fix: guard with |
|
@copilot, can you fix any outstanding comments and resolve any that have already been addressed? |
Done in 47181d8. Here's the status of each outstanding thread:
|
47181d8 to
28a2960
Compare
…o xref config, use local API in tests - Remove data-cite-section; use data-cite-frag (citeFrag) for section fragment - xref-headings.js: query a[data-cite-frag][data-matched-text] for section links and read conf.xref.headingApiUrl (nested under xref config) - data-cite.js: drop citeSection from toCiteDetails; use citeFrag && matchedText to identify section links for alias-application skip - dfn-index.js: drop citeFrag from inclusion condition — section links have no xrefType/linkType and no # in cite, so they're naturally excluded - type-helper.d.ts: add headingApiUrl to xref object type, remove xrefHeadingsUrl - tests: use xref.headingApiUrl local fixture for all [[[SPEC#id]]] tests; keep one production-API test; expand headings.json fixture with data-fetch entry Agent-Logs-Url: https://github.com/speced/respec/sessions/aa32a927-c840-432a-a14e-e761677cb37d
…ion links via matchedText check Agent-Logs-Url: https://github.com/speced/respec/sessions/b6df634f-8ac4-42c5-b5cc-58148b60b800
Fixed in b09c8f8. There were 3 failing tests caused by the
|
sidvishnoi
left a comment
There was a problem hiding this comment.
@copilot tests broken. Please address.
…ach(clearHeadingsData) in tests Agent-Logs-Url: https://github.com/speced/respec/sessions/8c82878b-0473-4392-a75b-8f86395664f7 Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
|
@copilot can you fix the issues CI found? |
…st to use local fixture Agent-Logs-Url: https://github.com/speced/respec/sessions/894f7dcc-7649-4771-a614-beba3fd743da Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
…ning Agent-Logs-Url: https://github.com/speced/respec/sessions/894f7dcc-7649-4771-a614-beba3fd743da Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
Fixed in f7a04da. The failing test ("uses heading text from API for [[[SPEC#id]]] when available") was hitting the production API and timing out in CI. Converted it to use the local fixture ( |
| const { result = [] } = await res.json(); | ||
| /** @type {Map<string, HeadingInfo>} */ | ||
| const fetched = new Map( | ||
| /** @type {{ spec: string, id: string, title: string, number: string | null, error?: boolean }[]} */ |
There was a problem hiding this comment.
Nit: extract this to a typedef.
There was a problem hiding this comment.
Done in ff74aa7 — added @typedef HeadingApiResultEntry and merged it with the existing HeadingInfo typedef block. The inline @type cast in fetchHeadingTexts now uses /** @type {HeadingApiResultEntry[]} */.
| * Must run after core/data-cite (so elements have href and spec-title fallback). | ||
| * @param {Conf} conf | ||
| */ | ||
| export async function run(conf) { |
There was a problem hiding this comment.
Nit: let's move this run() function to top (main on top, dependencies below it), matching rest of the plugins.
There was a problem hiding this comment.
Done in ff74aa7 — run() is now the first exported function, with getApiUrl(), fetchHeadingTexts(), and setHeadingContent() following it.
| const xrefConf = | ||
| typeof conf.xref === "object" && | ||
| conf.xref !== null && | ||
| !Array.isArray(conf.xref) | ||
| ? conf.xref | ||
| : {}; | ||
| const apiUrl = | ||
| typeof xrefConf.headingApiUrl === "string" | ||
| ? xrefConf.headingApiUrl | ||
| : HEADINGS_API_URL; |
There was a problem hiding this comment.
Nit: extract this into a function, getApiUrl(conf), so it's cleaner.
There was a problem hiding this comment.
Done in ff74aa7 — extracted getApiUrl(conf) helper function. run() now calls it with a single const apiUrl = getApiUrl(conf) line.
|
@copilot fix the nits? |
…piUrl() Agent-Logs-Url: https://github.com/speced/respec/sessions/3046c1c9-db26-4cee-9e17-15e70a809936 Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
Done in ff74aa7. All three nits addressed:
CI is passing on |
Agent-Logs-Url: https://github.com/speced/respec/sessions/3046c1c9-db26-4cee-9e17-15e70a809936 Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
Summary
[[[...]]]inline expansion syntax to allow[[[SPEC#fragment]]]#fragmentappended[[[fetch#data-fetch]]]→ link to the Fetch spec's#data-fetchsection, with link text taken from the spec titleTest plan
pnpm test:unit[[[fetch#data-fetch]]]produces a link tohttps://fetch.spec.whatwg.org/#data-fetch